Skip to content

Conversation

@jtschuster
Copy link
Member

@jtschuster jtschuster commented May 20, 2025

Preserve entitlements in the manages Mach-O signer for both regular apphost and singlefilehost.

Adds entitlements to singlefilehost during the build.

Refactors the signature blob types to be classes that implement IBlob. The various named blobs derive from SimpleBlob or SuperBlob (except for CodeDirectoryBlob which is more complex). SimpleBlob and SuperBlob provide methods for accessing info about the blobs and writing to a file. IMachFile is used for writing to allow reading and writing from/to a Stream or MemoryMappedViewAccessor.

The CodeSignature class was replaced with just the EmbeddedSignatureBlob, a SuperBlob containing other relevant signature blobs. Methods from the CodeSignature class were move to the relevant blob class.

HostWriter.SetAsBundle was moved to the Bundle class to avoid having to remap the memory mapped file multiple times. Since the host destination stream is never closed between creating the bundle and SetAsBundle / Signing the bundle, we don't need to create a new copy with a new inode to sign and replace the existing bundle.

cc @dotnet/appmodel

- Write out the updated symtab command when writing Mach-O file
- Pass macosCodesign through to test CreateAppHost methods
- Remove redundant `codesign` checks
- Warn when bundler is told to sign the bundle for a non-macos target
- Allow macosCodesign to be true for non-mac bundles
- Allow some padding between string table and signature
- Use the same memory-mapped file instance for placeholder replacement
  and signing
- formatting changes
@github-actions github-actions bot added the area-HostModel Microsoft.NET.HostModel issues label May 20, 2025
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @vitek-karas, @agocke
See info in area-owners.md if you want to be subscribed.

@jtschuster jtschuster requested a review from Copilot May 20, 2025 20:09
@jtschuster jtschuster linked an issue Jun 3, 2025 that may be closed by this pull request
@jtschuster jtschuster requested a review from Copilot June 3, 2025 20:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the Mach-O signing code to use class-based blob types, preserves entitlements (and DER entitlements) during signing, and streamlines how bundles and signatures are applied.

  • Introduce new BlobMagic entries for Entitlements and DerEntitlements.
  • Convert signature blob structs to an OO hierarchy (Blob, SimpleBlob, SuperBlob, etc.).
  • Update Bundler and HostWriter to preserve existing entitlements and avoid remapping files unnecessarily.

Reviewed Changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 1 comment.

File Description
src/installer/managed/Microsoft.NET.HostModel/MachO/Enums/BlobMagic.cs Add Entitlements and DerEntitlements magic constants.
src/installer/managed/Microsoft.NET.HostModel/MachO/BinaryFormat/LinkEditCommand.cs Rename struct to LinkEditLoadCommand.
src/installer/managed/Microsoft.NET.HostModel/Bundle/Bundler.cs Refactor bundle creation to use streams and memory‐mapped file; preserve entitlements.
src/installer/managed/Microsoft.NET.HostModel/AppHost/HostWriter.cs Consolidate signature handling and update method visibility.
Comments suppressed due to low confidence (3)

src/installer/managed/Microsoft.NET.HostModel/MachO/BinaryFormat/LinkEditCommand.cs:15

  • The file name 'LinkEditCommand.cs' no longer matches the updated struct name 'LinkEditLoadCommand'; consider renaming the file to 'LinkEditLoadCommand.cs' for consistency.
internal struct LinkEditLoadCommand

src/installer/managed/Microsoft.NET.HostModel/Bundle/Bundler.cs:281

  • The 'relativePathToSpec' dictionary is declared but never used; consider removing this variable to clean up unused code.
var relativePathToSpec = new Dictionary<string, FileSpec>(StringComparer.Ordinal);

src/installer/managed/Microsoft.NET.HostModel/MachO/BinaryFormat/Blobs/EmbeddedSignatureBlob.cs:170

  • This new method for calculating signature size and preserving entitlements could benefit from dedicated unit tests to validate size calculations across scenarios, including with and without existing entitlements.
internal static unsafe long GetSignatureSize(uint fileSize, string identifier, EmbeddedSignatureBlob? existingSignature, byte? hashSize = null)

- Don't use multiple levels of inheritance for blobs
- Add IMachOFileReader/Writer to abstract Stream and MemoryMappedViewAccessor based files
- Use IMachOFileReader/Writer as the interface for reading/writing to the disk for MachO files and blobs
@jtschuster
Copy link
Member Author

Superceded by #116566

@jtschuster jtschuster closed this Jul 2, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Aug 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-HostModel Microsoft.NET.HostModel issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codesigning the apphost on macOS should preserve entitlements

3 participants